<?php
namespace app\admin\controller;

use think\Controller;
use think\Db;
use think\Loader;
use think\Request;
use fast\lucn\Lucn;

/**
 * 文章管理
 *
 * @icon fa fa-circle-o
 */
class Copydata extends Controller
{
	
	    //搬运oscshop文章
	public function copy1(){ 
	    $list1 = Db::table('oscshop.osc_article')
		->where('cid','in',[10,11,16])
		->select();
		foreach($list1 as $i => $son){
		    $data['id'] = $son['article_id'];
			$data['category_id'] = $son['cid'];
			$data['title'] = $son['title'];
			$data['createtime'] = $son['date'];
			$data['updatetime'] = $son['date'];
			$data['author'] = $son['author'];
			$data['keywords'] = $son['tag'];
			$data['images'] = $son['images'];
			$data['views'] = $son['click'];
			$data['keywords'] = $son['tag'];
			$data['status'] = $son['click'] == 1 ? 'normal' : 'hidden';
			$one = Db::table('oscshop.osc_article_content')->where('article_id',$son['article_id'])->find();
			$data['content'] = $one['content'];
			$data['description'] = Lucn::msubstr(Lucn::nohtml($one['content']),0,100);
			$r = Db::name('article')->insert($data);
			echo $son['article_id'].'<br>';
		}
	}
	
	//搬运oscshop产品
	public function copy2(){ 
	    $list1 = Db::table('oscshop.osc_product')
		//->where('cid','in',[10,11,16])
		->select();
		foreach($list1 as $i => $son){
		    $data['id'] = $son['product_id'];
			$data['category_id'] = $son['cid'];
			$data['title'] = $son['title'];
			$data['createtime'] = $son['date'];
			$data['updatetime'] = $son['date'];
			//$data['author'] = $son['author'];
			$data['keywords'] = $son['tag'];
			$data['image'] = $son['thumb'];
			$data['images'] = $son['images'];
			$data['views'] = $son['viewed'];
			$data['status'] = $son['status'] == 1 ? 'normal' : 'hidden';
			//$one = Db::table('oscshop.osc_article_content')->where('article_id',$son['article_id'])->find();
			$data['content'] = $son['content'];
			//$data['description'] = Lucn::msubstr(Lucn::nohtml($one['content']),0,100);
			$data['description'] = Lucn::msubstr(Lucn::nohtml($son['content']),0,100);
			$r = Db::name('product')->insert($data);
			echo $son['product_id'].'<br>';
		}
	}
	
	//搬运minishop产品
	public function copy3(){ 
	    $list1 = Db::table('minishop.mini_product')
		//->where('cid','in',[10,11,16])
		->select();
		foreach($list1 as $i => $son){
		    $data['id'] = $son['id'];
			//$data['category_id'] = $son['cid'];
switch ($son['cid'])
{
case 7:
  $data['category_id'] = 4;
  break;  
case 8:
  $data['category_id'] = 5;
  break;
}
			$data['title'] = $son['title'];
			$data['createtime'] = $son['date'];
			$data['updatetime'] = $son['date'];
			//$data['author'] = $son['author'];
			$data['keywords'] = $son['tag'];
			$arr = json_decode($son['images'],true);
			$data['image'] = $arr[0];
			$data['images'] = implode(',',$arr);
			$data['views'] = $son['viewed'];
			$data['status'] = $son['status'] == 1 ? 'normal' : 'hidden';
			//$one = Db::table('oscshop.osc_article_content')->where('article_id',$son['article_id'])->find();
			$data['content'] = $son['content'];
			//$data['description'] = Lucn::msubstr(Lucn::nohtml($one['content']),0,100);
			$data['description'] = Lucn::msubstr(Lucn::nohtml($son['content']),0,100);
			$r = Db::name('product')->insert($data);
			echo $son['id'].'<br>';
		}
	}
	
	//改status为字母
	public function change1(){ 
	    $list = Db::name('article')->select();
		foreach($list as $i => $son){
		    $data['id'] = $son['id'];
		    $data['status'] = 'normal';
			$r = Db::name('article')->update($data);
			echo $son['id'].'<br>';
		}
	}
	
	//改images路径
	public function change2(){ 
	    $list = Db::name('article')->select();
		foreach($list as $i => $son){
		    $data['id'] = $son['id'];
			//$arr_img = json_decode($son['images'],true);
			/*foreach($arr_img as $i =>$son2){
			    str_replace('/mobile','',$son2);
			}*/
		    $images = $son['images'];
			$data['images'] = str_replace('/mobile/uploads/allimg','/uploads/allimg',$images);
			$r = Db::name('article')->update($data);
			echo $son['id'].'<br>';
		}
	}
	
	//改文章 content中图片路径
	public function change3(){ 
	    $list = Db::name('article')->select();
		foreach($list as $i => $son){
		    $data['id'] = $son['id'];
			//$arr_img = json_decode($son['images'],true);
			/*foreach($arr_img as $i =>$son2){
			    str_replace('/mobile','',$son2);
			}*/
		    $content = htmlspecialchars_decode($son['content']);
			$content = str_replace('/public/uploads/','/uploads/',$content);
			$data['content'] = $content;
			$r = Db::name('article')->update($data);
			echo $son['id'].'<br>';
		}
	}
	
	//改产品 content中图片路径
	public function change3p(){ 
	    $list = Db::name('product')->select();
		foreach($list as $i => $son){
		    $data['id'] = $son['id'];
			//$arr_img = json_decode($son['images'],true);
			/*foreach($arr_img as $i =>$son2){
			    str_replace('/mobile','',$son2);
			}*/
		    $content = htmlspecialchars_decode($son['content']);
			$content = str_replace('/public/uploads/','/uploads/',$content);
			$data['content'] = $content;
			$r = Db::name('product')->update($data);
			echo $son['id'].'<br>';
		}
	}
	
	//改产品 images 为逗号分隔
	public function change4(){ 
	    $list = Db::name('product')->select();
		foreach($list as $i => $son){
		    $data['id'] = $son['id'];
		    $images = $son['images'];
			$arr_img = explode(',',$images);
			if(count($arr_img)>0){
			    $data['image'] = $arr_img[0];
			}
			$r = Db::name('product')->update($data);
			echo $son['id'].'<br>';
		}
	}
	
	//改文章 content中 图片路径到public
	public function change5(){ 
	    $list = Db::name('article')->select();
		foreach($list as $i => $son){
		    $data['id'] = $son['id'];
			//$arr_img = json_decode($son['images'],true);
			/*foreach($arr_img as $i =>$son2){
			    str_replace('/mobile','',$son2);
			}*/
		    $content = $son['content'];
			$content = str_replace('/test1/fastadmin/public/','/public/',$content);
			$data['content'] = $content;
			$r = Db::name('article')->update($data);
			echo $son['id'].'<br>';
		}
		echo '<hr>';
		$list = Db::name('product')->select();
		foreach($list as $i => $son){
		    $data['id'] = $son['id'];
			//$arr_img = json_decode($son['images'],true);
			/*foreach($arr_img as $i =>$son2){
			    str_replace('/mobile','',$son2);
			}*/
		    $content = $son['content'];
			$content = str_replace('/test1/fastadmin/public/','/public/',$content);
			$data['content'] = $content;
			$r = Db::name('product')->update($data);
			echo $son['id'].'<br>';
		}
	}
	
	//改单页 content中 图片路径到public
	public function change6(){ 
	    $list = Db::name('page')->select();
		foreach($list as $i => $son){
		    $data['id'] = $son['id'];
			//$arr_img = json_decode($son['images'],true);
			/*foreach($arr_img as $i =>$son2){
			    str_replace('/mobile','',$son2);
			}*/
		    $content = $son['content'];
			$content = str_replace('/fastadmin1/public/','/public/',$content);
			$data['content'] = $content;
			$r = Db::name('page')->update($data);
			echo $son['id'].'<br>';
		}
	}
	
	//改黄花菜 content中图片路径
	public function change3h(){ 
	    $list = Db::name('hhc')->select();
		foreach($list as $i => $son){
		    $data['id'] = $son['id'];
			//$arr_img = json_decode($son['images'],true);
			/*foreach($arr_img as $i =>$son2){
			    str_replace('/mobile','',$son2);
			}*/
		    $content = $son['content'];
			$content = str_replace('/public/','/',$content);
			$data['content'] = $content;
			$r = Db::name('hhc')->update($data);
			echo $son['id'].'<br>';
		}
	}
}
